//原文链接：https://blog.csdn.net/ITSOK_123/article/details/124193057

//穷举：
class Solution {
public:
  vector<int> twoSum(vector<int>& nums, int t) {
    int len = nums.size();
    //两重循环遍历
    for(int i =0;i<len;i++){
        for(int j =i+1;j<len;j++){
        	//寻找加和为target的两个下标
            if(nums[i]+nums[j] == t)
                return {i,j};
        }
    }
    return {-1,-1};
  }
};

//哈希映射解法：
std::vector<int> twoSum(std::vector<int>& nums, int t) {
    std::unordered_map<int, int> seen;
    for (int i = 0; i < (int)nums.size(); ++i) {
    //在哈希map里面寻找是否存在满足与当前值相加为target的元素
      if (seen.find(nums[i]) != seen.end()) {
          return {seen[nums[i]],i};
      } else {
      //未找到则将本次的值插入，继续循环
        seen.insert({t - nums[i], i});
      }
    }
    return {-1, -1}; // error, not found
  }
